package com.xiaoxin.experience.service.net.model;

import com.xiaoxin.experience.util.StringUtil;

/**
 * @author xiaoxin
 */
public enum StorageUnitEnum
{
    BYTE{
        @Override
        public double toKB(double size)
        {
            return size/C2;
        }

        @Override
        public double toMB(double size)
        {
            return size/C3;
        }

        @Override
        public double toGB(double size)
        {
            return size/C4;
        }

        @Override
        public double toTB(double size)
        {
            return size/C5;
        }

        @Override
        public String toString(double size)
        {
            return StringUtil.floatFormat(size) + "B";
        }
    },

    KB {
        @Override
        public double toKB(double size)
        {
            return size;
        }

        @Override
        public double toMB(double size)
        {
            return size/C2;
        }

        @Override
        public double toGB(double size)
        {
            return size/C3;
        }

        @Override
        public double toTB(double size)
        {
            return size/C4;
        }

        @Override
        public String toString(double size)
        {
            return StringUtil.floatFormat(size) + "K";
        }
    },
    MB {
        @Override
        public double toKB(double size)
        {
            return size * C2;
        }

        @Override
        public double toMB(double size)
        {
            return size;
        }

        @Override
        public double toGB(double size)
        {
            return size/C2;
        }

        @Override
        public double toTB(double size)
        {
            return size/C3;
        }

        @Override
        public String toString(double size)
        {
            return StringUtil.floatFormat(size) + "M";
        }
    },
    GB {
        @Override
        public double toKB(double size)
        {
            return size * C3;
        }

        @Override
        public double toMB(double size)
        {
            return size * C2;
        }

        @Override
        public double toGB(double size)
        {
            return size;
        }

        @Override
        public double toTB(double size)
        {
            return size/C2;
        }

        @Override
        public String toString(double size)
        {
            return StringUtil.floatFormat(size) + "G";
        }
    },
    TB {
        @Override
        public double toKB(double size)
        {
            return size * C4;
        }

        @Override
        public double toMB(double size)
        {
            return size * C3;
        }

        @Override
        public double toGB(double size)
        {
            return size * C2;
        }

        @Override
        public double toTB(double size)
        {
            return size;
        }

        @Override
        public String toString(double size)
        {
            return StringUtil.floatFormat(size) + "T";
        }
    };

    static final long C1 = 1L;

    static final long C2 = C1 * 1024L;

    static final long C3 = C2 * 1024L;

    static final long C4 = C3 * 1024L;

    static final long C5 = C4 * 1024L;

    public double toKB(double size)
    {
        throw new AbstractMethodError();
    }
    public double toMB(double size)
    {
        throw new AbstractMethodError();
    }
    public double toGB(double size)
    {
        throw new AbstractMethodError();
    }
    public double toTB(double size)
    {
        throw new AbstractMethodError();
    }
    public String toString(double size)
    {
        throw new AbstractMethodError();
    }
}
